package com.xuecheng.manage_cms.controller;

import com.xuecheng.api.cms.CmsTemplateControllerApi;
import com.xuecheng.framework.domain.cms.CmsTemplate;
import com.xuecheng.framework.model.response.QueryResponseResult;
import com.xuecheng.framework.model.response.ResponseResult;
import com.xuecheng.manage_cms.service.CmsTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 站点管理
 */
@RestController
@RequestMapping("/cms/template")
public class CmsTemplateController implements CmsTemplateControllerApi {

    @Autowired
    private CmsTemplateService cmsTemplateService;
    /**
     * 新增站点
     * @param page
     * @param size
     * @param cmsTemplate
     * @return
     */
    @Override
    @GetMapping("/list/{page}/{size}")
    public QueryResponseResult findList(@PathVariable(name ="page") int page, @PathVariable("size") int size, CmsTemplate cmsTemplate) {
        return cmsTemplateService.findList(page,size,cmsTemplate);
    }

    /**
     * 查询所有站点信息
     * @return
     */
    @Override
    @GetMapping("/allList")
    public ResponseResult<List<CmsTemplate>> findAllList(){
        return cmsTemplateService.findAllList();
    }

    /**
     * 修改站点
     * @param cmsTemplate
     * @return
     */
    @Override
    @PostMapping("/add")
    public ResponseResult<CmsTemplate> add(@RequestBody CmsTemplate cmsTemplate) {
        return cmsTemplateService.add(cmsTemplate);
    }

    /**
     * 查询单个站点
     * @param id
     * @return
     */
    @Override
    @GetMapping("/get/{id}")
    public ResponseResult<CmsTemplate> findById(@PathVariable("id") String id) {
        return cmsTemplateService.findById(id);
    }


    @Override
    @PutMapping("/edit")
    public ResponseResult<CmsTemplate> edit(@RequestBody CmsTemplate cmsTemplate) {
        return cmsTemplateService.update(cmsTemplate);
    }


    /**
     * 删除站点
     * @param id
     * @return
     */
    @Override
    @DeleteMapping("/del/{id}")
    public ResponseResult delete(@PathVariable("id") String id) {
        return cmsTemplateService.delete(id);
    }
}
